﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CPPEI.Coolzon.Event.Core;
using CPPEI.Coolzon.Event.NCL;
using System.Windows.Controls;
using CPPEI.Coolzon.Metadata;
using CPPEI.Coolzon.UI;

namespace CPPEI.Coolzon.Theme.Fashion.MainViewControl
{
    public partial class SelectSceneView
    {
        [Common.Subscribe]
        public void OnOpened(CoreOpenSceneCompletedEvent @event)
        {
            _ShowingSceneName = @event.SceneName;
            this.Dispatcher.Invoke(() =>
            {
                Scene scene = SolutionUtil.GetScene(UIContext.Current.Solution, @event.SceneName);
                if (scene.Scenes == null || scene.Scenes.Count == 0)
                {
                    SubGrid.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    SubGrid.Visibility = System.Windows.Visibility.Visible;
                }
                SetCurrentScene(@event.SceneName);
            });
            if(UIContext.Current.OpenedSceneList == null)
            {
                UIContext.Current.OpenedSceneList = new Stack<string>();
            }
            if(@event.SwitchMode != UI.Data.SwitchMode.Pop && (UIContext.Current.OpenedSceneList.Count == 0 || !string.Equals(UIContext.Current.OpenedSceneList.Peek(), @event.SceneName)))
            {
                //记录历史场景，供返回功能使用
                UIContext.Current.OpenedSceneList.Push(@event.SceneName);
            }
        }
    }
}
